   yjx.service('browserJudge', ['$rootScope', '$location', 'ipCookie', '$timeout', '$locals', 'modalService',
    function ($rootScope, $location, ipCookie, $timeout, $locals, modalService) {//浏览器判断方法
        return {
            userAgent: function userAgent() {//浏览器用于 HTTP 请求的用户代理头的值
                return  window.navigator.userAgent.toLowerCase();
            },
            isWx: function isWx() {//是否为微信
                var ua = window.navigator.userAgent.toLowerCase();
                if (ua.match(/MicroMessenger/i) == 'micromessenger') {
                    return true;
                } else {
                    return false;
                }
            },
            isFirefox: function isWx() {//是否为微信
                var ua = window.navigator.userAgent.toLowerCase();
                if (ua.match(/firefox/i) == 'firefox') {
                    return true;
                } else {
                    return false;
                }
            },
            isSingleWindow: function isMultiWindow() {//是否为单层窗口浏览器
                var ua = window.navigator.userAgent.toLowerCase();
                //已知为单层打开窗口的浏览器
                //alert(ua);
                var swBrowsers = [
                    'micromessenger',
                    'browser',//手机自带浏览器一般都带有此标识
                ];
                var len = swBrowsers.length;
                for (var index = 0; index < len; index++) {
                    var item = swBrowsers[index];
                    var reg = new RegExp(item, 'i');
                    if (ua.match(reg) == item) {
                        //alert(ua.match(reg))
                        return true;
                    } else if (index >= len - 1) {//判断是否匹配到最后
                        //alert(index)
                        return false;
                    }
                }
            },
            plateform: function plateform() {//判断是PC端、移动端、ipad
                var ua = window.navigator.userAgent.toLowerCase();
                var pc = [
                    'msie',
                    'MSIE',
                    'windows nt',//微软windows
                    'Intel Mac OS',//苹果电脑
                    'intel mac OS',//苹果电脑
                    'intel mac os',//苹果电脑

                ];
                var ipad = [
                    'iPod',
                    'iPad',
                    'ipad',
                    'playbook',
                ];
                var mobile = [
                    'browser',//手机自带浏览器一般都带有此标识
                    'android',
                    'Android',
                    'Windows Phone',
                    'windows phone',
                    'hpwOS',
                    'hpwos',
                    'UCWEB',
                    'ucweb',
                    'Openwave',
                    'openwave',
                    'opera',
                    'blackBerry',
                    'blackberry',
                    'kfapwi',
                    'bb',
                    'msie',
                    'nokian9',
                    'mobile',
                    'meego',
                ];
                /*验证是否为pc*/
                var len = pc.length;

                for (var index = 0; index < len; index++) {
                    var item = pc[index];
                    var reg = new RegExp(item, 'i');
                    if (ua.match(reg) == item) {
                        return 'pc';
                    } else if (index >= len - 1) {//判断是否匹配到最后
                        //return false;
                    }
                }
                /*验证是否为ipad*/
                len = ipad.length;
                for (var index = 0; index < len; index++) {
                    var item = ipad[index];
                    var reg = new RegExp(item, 'i');
                    if (ua.match(reg) == item) {
                        //return 'ipad';
                        return 'pc';
                    } else if (index >= len - 1) {//判断是否匹配到最后
                        //return false;
                    }
                }
                /*验证是否为mobile*/

                len = mobile.length;
                for (var index = 0; index < len; index++) {
                    var item = mobile[index];
                    var reg = new RegExp(item, 'i');
                    if (ua.match(reg) == item) {
                        return 'mobile';
                    } else if (index >= len - 1) {//判断是否匹配到最后
                        return 'pc';
                    }
                }
            },
            changeDevice: function (type) {//更改浏览模式 pc mobile
                var ipCookiesParam = {expires: 1000, domain: DOMAIN, path: PATH};
                if (!ipCookie('user_device')) {
                    if (this.plateform() == 'mobile') {
                        ipCookie('user_device', 'mobile',ipCookiesParam);
                    } else {
                        ipCookie('user_device', 'pc',ipCookiesParam);
                    }
                }
                //var hostUrl = $location.$$absUrl;
                //var isPcUrl = (hostUrl + '').search('\/app\/') < 0;
                //var plateform = this.plateform();
                //if (isPcUrl) {
                //    if (plateform == 'mobile') {
                //        //跳转页面；
                //        self.location.href = 'http://www.aiekt.com/app/';
                //    }
                //}
            },
        }
    }
])
